//
//  WKAddAddressViewController.m
//  ourToken
//
//  Created by wakeup on 2018/5/31.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKAddAddressViewController.h"

@interface WKAddAddressViewController ()

@property (weak, nonatomic) IBOutlet UIButton *scanCodeBtn;
@property (weak, nonatomic) IBOutlet UIButton *btcBtn;//BTC按钮
@property (weak, nonatomic) IBOutlet UIButton *ethBtn;//ETH按钮
@property (weak, nonatomic) IBOutlet UITextField *name;//名称
@property (weak, nonatomic) IBOutlet UITextField *address;//地址
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;//保存按钮

@property (nonatomic, copy) NSString *coinType;//币种(ETH或BTC等)

@end

@implementation WKAddAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationView];
    [self layoutUI];
}

- (void)setNavigationView {
    [super setNavigationView];
    if (self.status == 0) {
        self.navigationView.topTitleLabel.text = @"添加地址";
    }
    else {
        self.navigationView.topTitleLabel.text = @"修改地址";
    }
}
- (IBAction)clickScanCodeBtn:(id)sender {
    WKScanCodeViewController *scanCode = [[WKScanCodeViewController alloc] init];
    [self.navigationController pushViewController:scanCode animated:YES];
}

- (void)layoutUI {
    self.btcBtn.backgroundColor = AppManager.themeColor;
    self.btcBtn.titleLabel.font = AppManager.btnFont;
    self.btcBtn.layer.cornerRadius = 5;
    self.btcBtn.layer.masksToBounds = YES;
    
    self.ethBtn.backgroundColor = [UIColor grayColor];
    self.ethBtn.titleLabel.font = AppManager.btnFont;
    self.ethBtn.layer.cornerRadius = 5;
    self.ethBtn.layer.masksToBounds = YES;
    
    self.saveBtn.backgroundColor = AppManager.themeColor;
    self.saveBtn.titleLabel.font = AppManager.btnFont;
    self.saveBtn.layer.cornerRadius = 5;
    self.saveBtn.layer.masksToBounds = YES;
    
    self.coinType = @"BTC";
    if (self.status == 1) {
        self.coinType = self.addressListModel.coinType;
        if ([self.coinType isEqualToString:@"ETH"]) {
            self.btcBtn.backgroundColor = [UIColor grayColor];
            self.ethBtn.backgroundColor = AppManager.themeColor;
        }
    }
}

//点击BTC按钮
- (IBAction)clickBtcBtn:(UIButton *)sender {
    self.btcBtn.backgroundColor = AppManager.themeColor;
    self.ethBtn.backgroundColor = [UIColor grayColor];
    self.coinType = @"BTC";
}

//点击ETH按钮
- (IBAction)clickEthBtn:(UIButton *)sender {
    self.btcBtn.backgroundColor = [UIColor grayColor];
    self.ethBtn.backgroundColor = AppManager.themeColor;
    self.coinType = @"ETH";
}

//点击保存按钮
- (IBAction)clickSaveBtn:(UIButton *)sender {
    if (self.status == 0) {
        //添加地址
        [httpManager addAddressWithCoinType:self.coinType name:self.name.text address:self.address.text success:^(NSDictionary *result) {
            
        } failure:^(NSError *error) {
            
        }];
    }
    else {
        //修改地址
        [httpManager updateAddressWithAddressId:self.addressListModel.id coinType:self.coinType name:self.name.text address:self.address.text success:^(NSDictionary *result) {
            
        } failure:^(NSError *error) {
            
        }];
    }
}
//收键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_name resignFirstResponder];
    [_address resignFirstResponder];
}
@end
